package com.flong.selenium;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

/***
 *@Author:liangjilong
 *@Date:2016年1月15日下午3:01:25
 *@Email:jilongliang@sina.com
 *@Version:1.0
 *@CopyRight(c)liangjilong
 *@Description:
 */
public class DoSelenium {
    static {
        Logger logger = Logger.getLogger("com.gargoylesoftware.htmlunit");
        logger.setLevel(Level.OFF);
    }

    public static void main(String[] args) throws IOException, Exception {
    	
    	//D:\\DevSoft\\chromedriver.exe  //HtmlUnitDriver driver = new HtmlUnitDriver();
    	System.setProperty("webdriver.chrome.driver", "D:\\DevSoft\\chromedriver.exe");
    	ChromeDriver driver = new ChromeDriver();
    	//设置访问ChromeDriver的路径
    	//driver.get("http://www.newrank.cn/public/info/search.html?value=play&isBind=false");
    	driver.get("http://www.newrank.cn/public/info/detail.html?account=touchbox");
    	
    	String pageSource = driver.getPageSource();
    	
    	String currentWindow = driver.getWindowHandle();  
        //得到所有窗口的句柄  
        Set<String> handles = driver.getWindowHandles();  
        Iterator<String> it = handles.iterator();  
        while(it.hasNext()){  
            String handle = it.next();  
            if(currentWindow.equals(handle)) continue;  
            WebDriver window = driver.switchTo().window(handle);  
            System.out.println("title,url = "+window.getTitle()+","+window.getCurrentUrl());  
        }  
    	
    	 List<WebElement> uls = driver.findElements(By.tagName("ul"));
    	 
    	 //只打印所有文本框的值
    	 String TextStr ="";
    	 for (Iterator iterator = uls.iterator(); iterator.hasNext();) {
				WebElement webElement = (WebElement) iterator.next();
				TextStr +=webElement.getText()+"\t";
				
				System.out.println(TextStr);
			
		}
    	 
    	 //跳转到百度这个请求链接
    	// driver.navigate().to("http://www.baidu.com");
    	 //回退可以说是返回上一个请求链接
    	 driver.navigate().back();
    	 //刷新页面请求
    	 driver.navigate().refresh();
    	 
    	//数据加载完之后，自动关闭浏览器.
    	//driver.close();
    	//driver.quit();
    	
    }

}
